<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <link href="./style.css" rel="stylesheet">
  <title>24.粘性导航特效</title>
</head>
<body>
  <header>
    <a href="#" class="logo">Logo</a>
    <ul>
      <li><a href="#">首页</a></li>
      <li><a href="#">关于</a></li>
      <li><a href="#">服务</a></li>
      <li><a href="#">作品</a></li>
      <li><a href="#">联系</a></li>
    </ul>
  </header>
  <section class="banner"></section>
  <script>
    window.addEventListener('scroll', () => {
      let header = document.querySelector('header')
      header.classList.toggle('sticky', window.scrollY > 0)
    })
  </script>
</body>
</html>